﻿using SourceStack.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SourceStack.Repositories
{
    public class ArticleRepository
    {
        private static IList<Article> articles;
        static ArticleRepository()
        {
            articles = new List<Article>
            {
                new Article
                {
                    Id=1 ,
                    Title=@"1-高阶",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=23,
                        Name="大飞哥"
                    },
                    PublishTime=new DateTime(2020,10,2,5,23,15)
                },
                 new Article
                {
                    Id=2 ,
                    Title=@"2-源栈线上学习须知",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=25,
                        Name="李硕"
                    },
                     PublishTime=new DateTime(2020,10,2,5,23,15)
                },
                   new Article
                {
                    Id=3 ,
                    Title=@"3-高阶",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=23,
                        Name="大飞哥"
                    },
                    PublishTime=new DateTime(2020,10,2,5,23,15)
                },
                 new Article
                {
                    Id=4 ,
                    Title=@"4-源栈线上学习须知",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=25,
                        Name="李硕"
                    },
                     PublishTime=new DateTime(2020,10,2,5,23,15)
                },  new Article
                {
                    Id=5 ,
                    Title=@"5-高阶",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=23,
                        Name="大飞哥"
                    },
                    PublishTime=new DateTime(2020,10,2,5,23,15)
                },
                 new Article
                {
                    Id=6 ,
                    Title=@"6-源栈线上学习须知",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=25,
                        Name="李硕"
                    },
                     PublishTime=new DateTime(2020,10,2,5,23,15)
                },
                     new Article
                {
                    Id=7 ,
                    Title=@"7-源栈线上学习须知",
                    Body=@"泛型方法可以有约束",
                    Author=new User
                    {
                        Id=25,
                        Name="李硕"
                    },
                     PublishTime=new DateTime(2020,10,2,5,23,15)
                },

            };
        }

        internal IList<Article> Get(int pageIndex, int pageSize)
        {
            return articles
                .Skip((pageIndex - 1) * pageSize)
                .Take(pageSize).ToList();
        }
        internal int GetCount()
        {
            return articles.Count();

        }
        public ArticleRepository()
        {

        }
        public Article Find(int id)
        {
            return articles.Where(a => a.Id == id).SingleOrDefault();
        }
        void Delete()
        {

        }
        //public int Save(Aritcle aritcle)
        //{

        //    aritcles.Add(aritcle);
        //}
    }

}